clear all
close all
clc
addpath('functions')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  This code generates Figure 1 of Gagnon and Jeanneret (2022): 
%  "How Does Corporate Governance Impact Equity Volatility? Worldwide Evidence and Theory"
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Load the regression coefficient estimates obtained with STATA

for i=1:2
    
    if i==1
series = 'Vol'; 
WithControlCoeff=[-3.87 -5.35 -14.14 -18.25];
NoControlCoeff=[-2.43 -3.75 -12.36 -15.95];
WithControlSE=[2.57 4.49 4.90 6.61];
NoControlSE=[3.24 5.15 5.87 7.88];
    else
series = 'Vol_ROA';
WithControlCoeff=[0.14 0.36 0.29 0.16];
NoControlCoeff=[0.17 0.34 0.23 0.02];
WithControlSE=[0.19 0.28 0.39 0.38];
NoControlSE=[0.18 0.30 0.39 0.38];
    end


%% Define the axes and the series
c = categorical({'t-1';'t';'t+1';'t+2'});
c = reordercats(c,{'t-1' 't' 't+1' 't+2'});

% Confidence intervals
Norm=norminv(0.95);
CI_C=WithControlSE.*Norm;
CI_NC=NoControlSE.*Norm;


figure
Height = 10.5; Width = 30; x0=0; y0=0;
set(gcf,'units','centimeters','PaperPositionMode','auto','Position',[x0,y0,Width,Height])
set(gcf,'color','w');

%% Subplot 1

subplot(1,2,1)
hold on
A=bar(c,WithControlCoeff,'BarWidth',0.5, 'BaseValue', 0.0, 'LineStyle','none');
set(A, 'FaceColor',[0.25, 0.40, 0.60]);
h=errorbar(c,WithControlCoeff,CI_C,'.','LineWidth', 1.3,'Color','r');
set(gca,'box','off')
set(gca,'FontSize',14)
set(gca, 'XTickLabel', {'t-1','t','t+1','t+2',''})
set(gca,'TickLabelInterpreter','latex')
hold off
grid on

% x-axis
xlabel('Timing of the reforms','FontSize',14,'Interpreter','latex'); 

% y-axis
ylabel('Change (\%)','FontSize',14,'Interpreter','latex')


% title
if strcmp(series,'Vol')==1
title('WITH CONTROLS (A)','FontSize',14,'Interpreter','latex');
ylim([-35 10])
elseif strcmp(series,'Vol_ROA')==1
title('WITH CONTROLS (C)','FontSize',14,'Interpreter','latex');
ylim([-1 1.5])
end 

% axis position
ax = gca;
op = ax.OuterPosition;
ti = (ax.TightInset); 
left = op(1) + 0.1*ti(1);
bottom = op(2) + 2*ti(2);
ax_width = op(3) - 0.5*ti(1) - ti(3);
ax_height = op(4) - ti(2) - 3*ti(4);
ax.Position = [left bottom ax_width ax_height];

%% Subplot 2

subplot(1,2,2)

% plot
hold on
A=bar(c,NoControlCoeff,'BarWidth',0.5, 'BaseValue', 0.0, 'LineStyle','none');
set(A, 'FaceColor',[0.25, 0.40, 0.60]);
h=errorbar(c,NoControlCoeff,CI_NC,'.','LineWidth', 1.3,'Color','r');
set(gca,'box','off')
set(gca,'FontSize',14)
set(gca, 'XTickLabel', {'t-1','t','t+1','t+2',''})
set(gca,'TickLabelInterpreter','latex')
hold off
grid on

% x-axis
xlabel('Timing of the reforms','FontSize',14,'Interpreter','latex'); 

% title
if strcmp(series,'Vol')==1
title('WITHOUT CONTROLS (B)','FontSize',14,'Interpreter','latex');
ylim([-35 10])
elseif strcmp(series,'Vol_ROA')==1
title('WITHOUT CONTROLS (D)','FontSize',14,'Interpreter','latex');
ylim([-1 1.5])
end 

% axis position
ax = gca;
op = ax.OuterPosition;
ti = (ax.TightInset); 
left = op(1) + 0.1*ti(1);
bottom = op(2) + 2*ti(2);
ax.Position = [left bottom ax_width ax_height];

% Set panel title
if strcmp(series,'Vol')==1
[h1]=suptitle('\textbf{EQUITY VOLATILITY}');
else
[h1]=suptitle('\textbf{ASSET VOLATILITY}');
end 
set(h1,'FontSize',14,'Interpreter','latex')

end
